﻿// ScanWindowDlg.cpp: 实现文件
//

#include "afxdialogex.h"
#include "ScanWindowDlg.h"
#include "../winapp/resource.h"
#include "YunDunDefenderDlg.h"
#include "../winapp/typedef.h"
#include "../module/InjectFramework.h"
// CScanWindowDialog 对话框

IMPLEMENT_DYNAMIC(CScanWindowDialog, CDialogEx)

CScanWindowDialog::CScanWindowDialog(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_SCANWINDOW, pParent)
{

}

CScanWindowDialog::~CScanWindowDialog()
{
}

void CScanWindowDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BUTTONTIMEOUT, m_ButtonTimeOut);
	DDX_Control(pDX, IDC_BUTTONSTOP, m_ButtonStop);
	DDX_Control(pDX, IDC_PROGRESS, m_progress);
	DDX_Control(pDX, IDC_PATH, m_path);
	DDX_Control(pDX, IDC_PROGRESS_DATABASE, m_pro_database);
	DDX_Control(pDX, IDC_PROGRESS_SCANFILE, m_pro_scan);
}


BEGIN_MESSAGE_MAP(CScanWindowDialog, CDialogEx)
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_BUTTONTIMEOUT, &CScanWindowDialog::OnBnClickedButtontimeout)
	ON_BN_CLICKED(IDC_BUTTONSTOP, &CScanWindowDialog::OnBnClickedButtonstop)
END_MESSAGE_MAP()


// CScanWindowDialog 消息处理程序


void CScanWindowDialog::OnSize(UINT nType, int cx, int cy)
{
	CDialogEx::OnSize(nType, cx, cy);
	if (m_ButtonTimeOut&&
		m_ButtonStop&&
		m_progress&&
		m_path&&
		m_pro_database&&
		m_pro_scan)
	{

		

		// Set the size and position of the button
		//m_ButtonDulldiskscan.SetWindowPos(NULL, nButtonLeft, nButtonTop, nButtonWidth, nButtonHeight, SWP_NOZORDER | SWP_NOACTIVATE);

		m_FontBold.CreateFont(cy * 0.08, 0, 0, 0, FW_BOLD,
			FALSE, FALSE, FALSE, DEFAULT_CHARSET,
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
			DEFAULT_PITCH | FF_SWISS, _T("Arial"));

		m_FontNormal.CreateFont(cy * 0.05, 0, 0, 0, FW_NORMAL,
			FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 
			CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, 
			_T("Arial"));
		
		m_progress.SetFont(&m_FontBold);
		m_path.SetFont(&m_FontNormal);
		auto nButtonWidth = cx * 0.5;
		auto nButtonHeight = cy * 0.11;
		auto nButtonLeft = cx * 0.05;
		auto nButtonTop = cy * 0.05;
		m_progress.SetWindowPos(NULL, nButtonLeft, nButtonTop, nButtonWidth, nButtonHeight, SWP_NOZORDER | SWP_NOACTIVATE);

		nButtonWidth = cx * 0.6;
		nButtonHeight = cy * 0.09;
		nButtonLeft = cx * 0.05;
		nButtonTop = cy * 0.2;
		m_path.SetWindowPos(NULL, nButtonLeft, nButtonTop, nButtonWidth, nButtonHeight, SWP_NOZORDER | SWP_NOACTIVATE);

		nButtonWidth = cx * 0.1;
		nButtonHeight = cy * 0.1;
		nButtonLeft = cx * 0.7;
		nButtonTop = cy * 0.1;
		m_ButtonStop.SetWindowPos(NULL, nButtonLeft, nButtonTop, nButtonWidth, nButtonHeight, SWP_NOZORDER | SWP_NOACTIVATE);

		nButtonWidth = cx * 0.1;
		nButtonHeight = cy * 0.1;
		nButtonLeft = cx * 0.85;
		nButtonTop = cy * 0.1;
		m_ButtonTimeOut.SetWindowPos(NULL, nButtonLeft, nButtonTop, nButtonWidth, nButtonHeight, SWP_NOZORDER | SWP_NOACTIVATE);

		nButtonWidth = cx * 0.7;
		nButtonHeight = cy * 0.2;
		nButtonLeft = cx * 0.15;
		nButtonTop = cy * 0.35;
		m_pro_database.SetWindowPos(NULL, nButtonLeft, nButtonTop, nButtonWidth, nButtonHeight, SWP_NOZORDER | SWP_NOACTIVATE);

		nButtonWidth = cx * 0.7;
		nButtonHeight = cy * 0.2;
		nButtonLeft = cx * 0.15;
		nButtonTop = cy * 0.6;
		m_pro_scan.SetWindowPos(NULL, nButtonLeft, nButtonTop, nButtonWidth, nButtonHeight, SWP_NOZORDER | SWP_NOACTIVATE);
	}
	// TODO: 在此处添加消息处理程序代码
	
}


void CScanWindowDialog::OnBnClickedButtontimeout()
{
	// TODO: 在此添加控件通知处理程序代码
	CString cst_text;
	m_ButtonTimeOut.GetWindowText(cst_text);
	if (cst_text.Compare(BUTTO_NAME_TIMEOUT) == 0)
	{
		m_ButtonTimeOut.SetWindowText(BUTTO_NAME_CONTINUE);
		auto& framewk = ProcessFramework::instance();
		framewk.pause_work();
	}
	else
	{
		m_ButtonTimeOut.SetWindowText(BUTTO_NAME_TIMEOUT);
		auto& framewk = ProcessFramework::instance();
		framewk.resume_work();
	}
}


void CScanWindowDialog::OnBnClickedButtonstop()
{
	// TODO: 在此添加控件通知处理程序代码
	if (m_pParentDlg != nullptr)
	{
		auto& framewk = ProcessFramework::instance();
		framewk.stop_work();
	}
}

void CScanWindowDialog::SetProgress(std::wstring& w_porcess)
{
	m_progress.SetWindowText(w_porcess.c_str());
}

void CScanWindowDialog::SetPath(std::wstring& w_path)
{
	m_path.SetWindowText(w_path.c_str());
}

void CScanWindowDialog::SetForProgress(DWORD& dwclt)
{
	if (dwclt == 0)
	{
		m_pro_scan.SetBarColor(RGB(0, 0, 255)); // 设置进度条颜色为红色
		m_pro_scan.SetBkColor(RGB(255, 255, 255)); // 设置背景颜色为白色
	}
	m_pro_scan.SetPos(dwclt);
}

void CScanWindowDialog::SetForDatabase(DWORD& dwclt)
{
	if (dwclt == 0)
	{
		m_error = 0;
		m_pro_database.SetBarColor(RGB(0, 0, 255)); // 设置进度条颜色为红色
		m_pro_database.SetBkColor(RGB(255, 255, 255)); // 设置背景颜色为白色
	}
	m_pro_database.SetPos(dwclt);
}

void CScanWindowDialog::AddScanColor(DWORD& dwclt)
{
	if (m_error + dwclt < 255 )
	{
		m_error += dwclt;
		m_pro_scan.SetBarColor(RGB(m_error, 0, 0)); // 设置进度条颜色为红色
	}
	
	m_pro_scan.SetBkColor(RGB(255, 255, 255)); // 设置背景颜色为白色
}